package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.greattrade.GreatTradeMgr;

import java.util.ArrayList;
import java.util.List;

public class GreatTradeRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = GreatTradeMgr.getActivityInfo();
        if(activityInfo != null){
            addRecycleItemData(activityInfo, eItemId.GREAT_TRADE_JI_CHENG_DIAN.getValue());
        }
    }

    private void addRecycleItemData(ActivityInfo activityInfo, int itemId) {
        List<String> paramList = new ArrayList<>();
        long recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
        paramList.add(String.valueOf(itemId));
        paramList.add(String.valueOf(GameConfig.GAME_MONEY_INGOTS));
        paramList.add("0");
        paramList.add(activityInfo.getActivityName());
        ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 3, recycleTime, paramList);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.GreatTradeActivity.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        //String titleKey = MailManager.ACTIVITY_GOODS_AUTO_CONSUME_TITLE;
        //String contentKey = MailManager.ACTIVITY_GOODS_AUTO_CONSUME_CONTENT;
        //item2Score(userId, data, titleKey, contentKey);
        UserBagItem item = getUserBagItem(userId, data.getItemId());
        if(item != null && item.getNum() > 0){
            removeItem(item);
        }
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = GreatTradeMgr.getActivityInfo();
        if(activityInfo == null){
            GreatTradeMgr.getLogger().error("GreatTrade Recycle Fail, Because ActivityInfo is null");
            return false;
        }
        return ActivityMgr.activityInTime(activityInfo);
    }
}
